package com.gxh.controller.admin;

import com.gxh.dto.RequestMachinePageQueryDTO;
import com.gxh.dto.UploadMachinePageQueryDTO;
import com.gxh.result.PageResult;
import com.gxh.result.Result;
import com.gxh.service.UserMachineService;
import com.gxh.vo.UserMachineDetailVO;
import com.gxh.vo.UserRequestMachineDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminUserMachineController")
@RequestMapping("/admin/user_machine")
@Api(tags = "管理端用户设备接口")
@Slf4j
public class UserMachineController {


    @Autowired
    private UserMachineService userMachineService;

    /**
     * 用户上传设备分页查询
     * @param uploadMachinePageQueryDTO
     * @return
     */
    @GetMapping("/upload/page")
    @ApiModelProperty("用户上传设备分页查询")
    public Result<PageResult> uploadPage(UploadMachinePageQueryDTO uploadMachinePageQueryDTO){
        log.info("用户上传设备分页查询{}" , uploadMachinePageQueryDTO);
        PageResult pageResult = userMachineService.uploadPage(uploadMachinePageQueryDTO);
        return Result.success(pageResult);
    }


    /**
     * 用户上传设备详情
     * @param id
     * @return
     */
    @GetMapping("/upload/{id}")
    @ApiModelProperty("用户上传设备详情")
    public Result<UserMachineDetailVO> uploadDetail(@PathVariable Long id){
        log.info("用户上传设备详情{}" , id);
        UserMachineDetailVO userMachineDetailVO = userMachineService.uploadDetail(id);
        return Result.success(userMachineDetailVO);
    }



    /**
     * 用户上传设备处理
     * @param status
     * @param id
     * @return
     */
    @PutMapping("/upload/{status}")
    @ApiModelProperty("用户上传设备处理")
    public Result status(@PathVariable Integer status, @RequestParam Long id){
        log.info("用户上传设备处理{}" , status);
        userMachineService.uploadStatus(status, id);
        return Result.success();
    }

    /**
     * 批量删除用户上传设备
     * @param ids
     * @return
     */
    @DeleteMapping("/upload")
    @ApiModelProperty("批量删除用户上传设备")
    public Result delete(@RequestBody List<Long> ids){
        log.info("批量删除用户上传设备{}" , ids);
        userMachineService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 用户求购设备分页查询
     * @param requestMachinePageQueryDTO
     * @return
     */
    @GetMapping("/request/page")
    @ApiModelProperty("用户求购设备分页查询")
    public Result<PageResult> requestPage(RequestMachinePageQueryDTO requestMachinePageQueryDTO){
        log.info("用户求购设备分页查询{}" , requestMachinePageQueryDTO);
        PageResult pageResult = userMachineService.requestPage(requestMachinePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 用户求购设备详情
     * @param id
     * @return
     */
    @GetMapping("/request/{id}")
    @ApiModelProperty("用户求购设备详情")
    public Result<UserRequestMachineDetailVO> requestDetail(@PathVariable Long id){
        log.info("用户求购设备详情{}" , id);
        UserRequestMachineDetailVO userRequestMachineDetailVO = userMachineService.requestDetail(id);
        return Result.success(userRequestMachineDetailVO);
    }

    /**
     * 用户求购设备处理
     * @param status
     * @param id
     * @return
     */
    @PutMapping("/request/{status}")
    @ApiModelProperty("用户求购设备处理")
    public Result requestStatus(@PathVariable Integer status, @RequestParam Long id){
        log.info("用户求购设备处理{}" , status);
        userMachineService.requestStatus(status, id);
        return Result.success();
    }

    /**
     * 批量删除用户求购设备
     * @param ids
     * @return
     */
    @DeleteMapping("/request")
    @ApiModelProperty("批量删除用户求购设备")
    public Result deleteRequest(@RequestBody List<Long> ids){
        log.info("批量删除用户求购设备{}" , ids);
        userMachineService.deleteRequestBatch(ids);
        return Result.success();
    }

}
